using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SnowLotus.Canvas
{
    public class SL2Line:SL2Base
    {
        private Line mline;
      
        public Line Shape
        {
            get { return mline; }
        }

        public SL2Line(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0, double strokeThickness = 1, Brush stroke = null)
        {
            mline = new Line();

            Manager.AddShape(mline);
            mline.StrokeThickness = strokeThickness;
            // 设置默认的 Stroke
            if (stroke != null)
            {
                mline.Stroke = stroke;
            }
            else
            {
                mline.Stroke = Brushes.Black;
            }

            setStartPoint(x1, y1);
            setEndPoint(x2, y2);

        }

       

        public void setStartPoint(double x, double y)
        {
            mline.X1 = x;
            mline.Y1 = y;


        }


        public override void move(double mx, double my)
        {
            System.Windows.Controls.Canvas.SetLeft(mline,mx);
            System.Windows.Controls.Canvas.SetTop(mline,my);

            //mline.X1 += mx;
            //mline.Y1 += my;
            //mline.X2 += mx;
            //mline.Y2 += my; 
        }



        public override void rotate(double angle, RotateDirection rotateDirection = RotateDirection.Center)
        {
            RotateTransform rotateTransform = new RotateTransform(angle);
            if (rotateDirection == RotateDirection.Center)
            {

                rotateTransform.CenterX = (mline.X1 + mline.X2) / 2;
                rotateTransform.CenterY = (mline.Y1 + mline.Y2) / 2;
            }
            else if (rotateDirection == RotateDirection.Start)
            {
                rotateTransform.CenterX = mline.X1;
                rotateTransform.CenterY = mline.Y1;
            }
            else if (rotateDirection == RotateDirection.End)
            {
                rotateTransform.CenterX = mline.X2;
                rotateTransform.CenterY = mline.Y2;
            }
            mline.RenderTransform = rotateTransform;

        }


        public void setEndPoint(double x, double y)
        {
            mline.X2 = x;
            mline.Y2 = y;
        }







    }
}
